package cn.javacc.nav.service;

import javax.inject.Inject;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.javacc.core.util.Hql;
import cn.javacc.core.vo.PageData;
import cn.javacc.nav.dao.CategoryDao;
import cn.javacc.nav.domain.Category;
import cn.javacc.util.Status;

@Service
public class CategoryService {
	private CategoryDao categoryDao;

	public Category getCategoryById(Long id) {
		Category category = this.categoryDao.get(id);
		if (category != null && category.getStatus() == Status.NORMAL) {
			return category;
		}
		return null;
	}

	public PageData<Category> query(Integer toPage, Integer pageSize) {
		return this.categoryDao.queryForPage(Hql.Start("from Category"), toPage, pageSize);
	}

	@Transactional
	public void saveCategory(Category category) {
		this.categoryDao.save(category);
	}

	@Transactional
	public void updateCategory(Category category) {
		this.categoryDao.update(category);
	}

	@Transactional
	public void deleteCategory(Long id) {
		this.categoryDao.delete(id);
	}

	@Inject
	public void setCategoryDao(CategoryDao categoryDao) {
		this.categoryDao = categoryDao;
	}
}
